package com.mall.cart.Interceptor;

import com.common.constants.AuthConstant;
import com.common.vo.MemberVo;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class AuthInterceptor implements HandlerInterceptor {
   public final static ThreadLocal<MemberVo> threadLocal = new ThreadLocal<>();
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        Object attribute = session.getAttribute(AuthConstant.AUTH_SESSION_REDIS);
        if (attribute != null){
            MemberVo vo = (MemberVo) attribute;
            threadLocal.set(vo);
        }
        return true;
    }
}
